from django.db import models

# Create your models here.
class  Teacher(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=20)
    age = models.IntegerField()
    class Meta:
        db_table = 'Teacher'
        verbose_name = '老师表'
        verbose_name_plural = verbose_name



class TeacherDetail(models.Model):
    SEX_TYPE = (
        (0,'男'),
        (1,'女')
    )
    birthday = models.DateField()
    sex = models.IntegerField(default=0,choices=SEX_TYPE)
    phone = models.CharField(max_length=11)
    address = models.CharField(max_length=40)
    hiredate = models.DateField()


    # 建立和老师表一对一的关系
    # models.CASCADE  # 设置级联删除
    # 删除主表中的数据，副表中关联的数据一起删除
    # models.DO_NOTHING: 删除主表中的数据，副表数据不影响，有异常出现
    # models.SET_DEFAULT: 需要配合default = 1
    # models.SET_NULL: 删除主表中的数据，副表数据设置为null

    teacher = models.OneToOneField("Teacher",on_delete=models.CASCADE)

    class   Meta:
        db_table = 'TeacherDetail'



class Dept(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=20)
    class Meta:
        db_table = 'Dept'
        verbose_name ='部门表'
        verbose_name_plural = verbose_name



class Course(models.Model):
    name = models.CharField(max_length=20)
    num = models.IntegerField()



    dept = models.ForeignKey('Dept',on_delete=models.CASCADE)

    teacher = models.ManyToManyField('Teacher')

    class Meta:
        db_table = 'Course'
        verbose_name = '课程表'
        verbose_name_plural = verbose_name